// Decompiled with JetBrains decompiler
// Type: ByteArrayUtil
// Assembly: FMCommon, Version=1.0.8663.21262, Culture=neutral, PublicKeyToken=null
// MVID: 52773074-FB09-4BA0-8FA9-4782D11D6C17
// Assembly location: /Users/mac/work/RiverGame/com.rivergame.fmframework/Runtime/Plugins/FMCommon.dll

public class ByteArrayUtil
{
  public static byte[] intToBytes(int x)
  {
    return new byte[4]
    {
      (byte) (x >> 24),
      (byte) (x >> 16),
      (byte) (x >> 8),
      (byte) x
    };
  }

  public static void intCopyToBytes(int x, byte[] bytes, ref int pos)
  {
    bytes[pos] = (byte) (x >> 24);
    ++pos;
    bytes[pos] = (byte) (x >> 16);
    ++pos;
    bytes[pos] = (byte) (x >> 8);
    ++pos;
    bytes[pos] = (byte) x;
    ++pos;
  }

  public static byte[] shortToByteArray(short s)
  {
    return new byte[2]
    {
      (byte) ((uint) s >> 8),
      (byte) ((uint) s & (uint) byte.MaxValue)
    };
  }

  public static void shortCopyToByteArray(short s, byte[] bytes, ref int pos)
  {
    bytes[pos] = (byte) ((uint) s >> 8);
    ++pos;
    bytes[pos] = (byte) ((uint) s & (uint) byte.MaxValue);
    ++pos;
  }

  public static int bytesToInt(byte[] bytes)
  {
    return ((int) bytes[0] & (int) byte.MaxValue) << 24 | ((int) bytes[1] & (int) byte.MaxValue) << 16 | ((int) bytes[2] & (int) byte.MaxValue) << 8 | (int) bytes[3] & (int) byte.MaxValue;
  }

  public static int readInt(byte[] bytes, ref int offset)
  {
    int num = ((int) bytes[offset] & (int) byte.MaxValue) << 24 | ((int) bytes[offset + 1] & (int) byte.MaxValue) << 16 | ((int) bytes[offset + 2] & (int) byte.MaxValue) << 8 | (int) bytes[offset + 3] & (int) byte.MaxValue;
    offset += 4;
    return num;
  }

  public static short readShort(byte[] bytes, ref int offset)
  {
    int num = (int) (short) (((int) bytes[offset] & (int) byte.MaxValue) << 8 | (int) bytes[offset + 1] & (int) byte.MaxValue);
    offset += 2;
    return (short) num;
  }
}
